package com.blandware.atleap.webapp.form.questionnaire;

import javax.servlet.http.HttpServletRequest;
import com.blandware.atleap.webapp.form.BaseForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;
import java.util.Map;
import java.util.HashMap;

/**
 * @struts.form name="questionForm" 
 */
public  class QuestionForm
    extends    BaseForm
    implements java.io.Serializable
{

    protected String id;

    protected String questionnaireId;

    protected String type;

    protected Boolean required;

    protected String validationRegex;

    protected String version;

    protected Map titleMap;

    /** Default empty constructor. */
    public QuestionForm() {}

    public String getId()
    {
        return this.id;
    }

   /**
    */
    public void setId(String id)
    {
        this.id = id;
    }

    public String getQuestionnaireId()
    {
        return this.questionnaireId;
    }

   /**
    */
    public void setQuestionnaireId(String questionnaireId)
    {
        this.questionnaireId = questionnaireId;
    }

    public String getType()
    {
        return this.type;
    }

   /**
    * @struts.validator type="required"
    */
    public void setType(String type)
    {
        this.type = type;
    }

    public Boolean getRequired()
    {
        return this.required;
    }

   /**
    */
    public void setRequired(Boolean required)
    {
        this.required = required;
    }

    public String getValidationRegex()
    {
        return this.validationRegex;
    }

   /**
    */
    public void setValidationRegex(String validationRegex)
    {
        this.validationRegex = validationRegex;
    }

    public String getVersion()
    {
        return this.version;
    }

   /**
    */
    public void setVersion(String version)
    {
        this.version = version;
    }

    public Map getTitleMap()
	{
		return this.titleMap;
	}
    public Object getTitle(String key)
	{
		return this.titleMap != null ? this.titleMap.get(key) : null;
	}

   /**
    */
    public void setTitleMap(Map titleMap)
	{
		this.titleMap = titleMap;
	}
    public void setTitle(String key, Object value)
	{
		if ( this.titleMap == null ) {
			this.titleMap = new HashMap();
		}
		this.titleMap.put(key, value);
	}

    /**
     * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping,
     *                                                javax.servlet.http.HttpServletRequest)
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // reset any boolean data types to false

        this.required = Boolean.FALSE;

        // reset all linking properties to null

        this.questionnaireId = null;

// reset all mapped properties to default values

		this.titleMap = new HashMap();

    }

	protected Map titleCheckedBoxes = java.util.Collections.synchronizedMap(new HashMap());

	protected String localesMode = null;

	protected String regexFromList = null;

	public Map getTitleCheckedBoxes() {
		return titleCheckedBoxes;
	}

	public void setTitleCheckedBoxes(Map titleCheckedBoxes) {
		this.titleCheckedBoxes = titleCheckedBoxes;
	}

	/**
	 * Returns true, if checkbox was checked
	 *
	 * @param key Key to look for. If it is exists in map, <code>Boolean.TRUE</code> will be returned
	 * @return <code>Boolean.TRUE</code> if key exists in map, and <code>Boolean.FALSE</code> otherwise
	 */
	public Object getTitleCheckedBox(String key) {
		if ( titleCheckedBoxes.containsKey(key) ) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	/**
	 * Puts key in map
	 *
	 * @param key   Key to associate value with
	 * @param value Value to put for specified key
	 */
	public void setTitleCheckedBox(String key, Object value) {
		titleCheckedBoxes.put(key, value);
	}

    public void setLocalesMode(String mode) {
        localesMode = mode;
    }

    public String getLocalesMode() {
        return localesMode;
    }

    /**
     * Decides whether 'check all checkboxes' checkbox need to be checked or
     * not (for title locale checkboxes)
     *
     * @param request processed request
     * @param localesMode locales mode being used
     */
    public void setAllCheckedFlagForTitleCheckboxes(HttpServletRequest request, String localesMode) {
        if ("selected".equalsIgnoreCase(localesMode)) {
            Boolean checkAllIsChecked;
            java.util.List locales = (java.util.List) request.getSession().getAttribute(com.blandware.atleap.webapp.util.core.WebappConstants.CONTENT_LOCALES_COLLECTION_KEY);
            checkAllIsChecked = getTitleCheckedBoxes().size() == locales.size() ? Boolean.TRUE : Boolean.FALSE;
            request.setAttribute(com.blandware.atleap.webapp.util.core.WebappConstants.SELECT_ALL_LOCALES_CHECKBOX_IS_CHECKED, checkAllIsChecked);
        }
    }

    public void setRegexFromList(String value) {
        regexFromList = value;
    }

    public String getRegexFromList() {
        return regexFromList;
    }
}
